from fastapi import Body, FastAPI

import api.service.knowledgebase_service as knowledgebase_service
from api.vo.form.knowledge_form import KnowledgebaseForm
from api.vo.query.knowledgebase_query import KnowledgebaseQuery

async def exist(name: str=Body(..., description="知识库名称", embed=True),
                id: str=Body(default=None, description="知识库ID", embed=True)):
    return knowledgebase_service.exists(name=name, id=id)

async def add(knowledge: KnowledgebaseForm) :
    return knowledgebase_service.add(knowledgeForm=knowledge)

async def enable(idList: list = Body(..., description="ID", embed=True)):
    return knowledgebase_service.enabled(idList=idList)

async def disabled(idList: list = Body(..., description="ID", embed=True)):
    return knowledgebase_service.disabled(idList=idList)


async def deletes(idList: list = Body(..., description="ID", embed=True)) :
    return knowledgebase_service.deletes(idList=idList)

async def list(knowledgebase: KnowledgebaseQuery) :
    return knowledgebase_service.list(knowledgebase)

async def update(knowledgeForm: KnowledgebaseForm) :
    return knowledgebase_service.update(knowledgeForm = knowledgeForm)

async def get(id: str) :
    print("id = " + id)
    return knowledgebase_service.get(id=id)

def add_knowledgebase_routes(app: FastAPI) :
    app.post("/knowledgebase/add", summary="增加知识库", description="增加知识库")(add)
    app.post("/knowledgebase/update", summary="增加知识库", description="增加知识库")(update)
    app.delete("/knowledgebase/delete", summary="删除知识库", description="删除知识库")(deletes)
    app.post("/knowledgebase/list", summary="列表展示知识库", description="列表展示知识库")(list)
    app.put("/knowledgebase/rename", summary="重命名知识库", description="重命名知识库")(update)
    app.put("/knowledgebase/enable", summary="启用知识库", description="启用知识库")(enable)
    app.put("/knowledgebase/disable", summary="禁用知识库", description="禁用知识库")(disabled)
    app.post("/knowledgebase/exist", summary="知识库是否存在", description="知识库是否存在")(exist)
    app.get("/knowledgebase/{id}", summary="通过ID获取知识库", description="通过ID获取知识库")(get)

